<!--
描述：楼房信息-新增组件
开发人：fwb
开发日期：2017年8月22日
-->

<template lang="pug">
    kalix-dialog.user-add(bizKey="examScore" ref="kalixBizDialog" v-bind:form-model.sync="formModel" v-bind:targetURL="targetURL_Score")
        div.el-form(slot="dialogFormSlot")
            div.s-flex
                el-form-item.s-flex_item(label="条形码" prop="barCode" v-bind:rules="rules.barCode" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.barCode" v-on:blur="getInfo" ref="barCode_input" v-focus="true" v-on:input="cleanInfo")
            div.s-flex
                el-form-item.s-flex_item(label="考号" prop="examNumber" v-bind:rules="rules.examNumber" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.examNumber" v-bind:disabled="disabled")
                el-form-item.s-flex_item(label="考生姓名" prop="examName" v-bind:rules="rules.examName" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.examName" v-bind:disabled="disabled")
            <!--div.s-flex-->
                <!--el-form-item.s-flex_item(label="身份证" prop="identificationCard" v-bind:label-width="labelWidth")-->
                    <!--el-input(v-model="formModel.identificationCard" v-bind:disabled="disabled")-->
                <!--el-form-item.s-flex_item(label="专业" prop="major" v-bind:label-width="labelWidth")-->
                    <!--kalix-dict-select(v-model="formModel.major" appName="enrolment" dictType="考生专业" v-bind:disabled="disabled")-->
            <!--div.s-flex-->
                <!--el-form-item.s-flex_item(label="毕业院校" prop="university" v-bind:label-width="labelWidth")-->
                    <!--el-input(v-model="formModel.university" v-bind:disabled="disabled")-->
                <!--el-form-item.s-flex_item(label="联系地址" prop="address" v-bind:label-width="labelWidth")-->
                    <!--el-input(v-model="formModel.address" v-bind:disabled="disabled")-->
            <!--div.s-flex-->
                <!--el-form-item.s-flex_item(label="联系电话" prop="phone" v-bind:label-width="labelWidth")-->
                    <!--el-input(v-model="formModel.phone" v-bind:disabled="disabled")-->
                <!--el-form-item.s-flex_item(label="省份" prop="province" v-bind:label-width="labelWidth")-->
                    <!--el-input(v-model="formModel.province" v-bind:disabled="disabled")-->
            div.s-flex
                el-form-item.s-flex_item(label="专业" prop="major" v-bind:label-width="labelWidth")
                    kalix-dict-select(v-model="formModel.major" appName="enrolment" dictType="考生专业" v-bind:disabled="disabled")
                el-form-item.s-flex_item(label="省份" prop="province" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.province" v-bind:disabled="disabled")
            div.s-flex(v-if="show")
                el-form-item.s-flex_item(v-bind:label="score_name" prop="artScore" v-bind:rules="rules.artScore" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.artScore")
                el-form-item.s-flex_item(v-bind:label="score_name_1" prop="storyScore" v-bind:rules="rules.storyScore" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.storyScore")
            div.s-flex
                el-form-item.s-flex_item(label="总分" prop="totalScore" v-bind:rules="rules.totalScore" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.totalScore")
                el-form-item.s-flex_item(label="成绩备注" prop="remark" v-bind:rules="rules.remark" v-bind:label-width="labelWidth")
                    kalix-dict-select(v-model="formModel.remark" appName="enrolment" dictType="成绩备注")
</template>

<script type="text/ecmascript-6">
    import FormModel from './examScoreModel.js'
    import {ExamScoreURL, ExamStudentBarCodes} from '../../config.toml'

    export default {
        name: 'ExamScoreAdd',
        data() {
            return {
                formModel: Object.assign({}, FormModel),
                rules: {
                    barCode: [{required: true, message: '条形码不能为空', trigger: 'blur'}],
                    examNumber: [{required: true, message: '考号不能为空', trigger: 'blur'}],
                    examName: [{required: true, message: '考生姓名不能为空', trigger: 'blur'}],
                    artScore: [{
                        type: 'number', required: true, message: '成绩必须是数字', trigger: 'change', transform(value) {
                            return Number(value);
                        }
                    }],
                    storyScore: [{
                        type: 'number', required: true, message: '成绩必须是数字', trigger: 'change', transform(value) {
                            return Number(value);
                        }
                    }],
                    totalScore: [{
                        type: 'number', required: true, message: '成绩必须是数字', trigger: 'change', transform(value) {
                            return Number(value);
                        }
                    }],
                    remark: [{required: true, message: '请选择成绩备注', trigger: 'change'}]
                },
                targetURL: ExamStudentBarCodes,
                targetURL_Score: ExamScoreURL,
                labelWidth: '120px',
                disabled: true,
                score_name: '文艺常识',
                score_name_1: '故事编写',
                barCode: '',
                show: true
            }
        },
        watch: {
            formModel: {
                handler: 'watchFormModel',
                deep: true
            }
        },
        components: {},
        created() {
        },
        directives: {
            focus: {
                inserted: function (el) {
                    el.querySelector('input').focus()
                }
            }
        },
        methods: {
            watchFormModel(newVal) {
                if (this.formModel.artScore !== undefined && this.formModel.storyScore !== undefined) {
                    this.formModel.totalScore = Number(this.formModel.artScore) + Number(this.formModel.storyScore)
                }
            },
            getInfo() {
                if (this.formModel.barCode !== '') {
                    this.axios.request({
                        method: 'get',
                        url: this.targetURL,
                        //  data: this.formModel,
                        params: {barCode: this.formModel.barCode}
                    }).then(response => {
                        if (response.data.data) {
                            this.formModel.examNumber = response.data.data[0].examNumber
                            this.formModel.examName = response.data.data[0].examName
                            this.formModel.identificationCard = response.data.data[0].identificationCard
                            this.formModel.major = response.data.data[0].major
                            this.formModel.province = response.data.data[0].province
                            this.formModel.university = response.data.data[0].university
                            this.formModel.address = response.data.data[0].address
                            this.formModel.phone = response.data.data[0].phone

                            if (this.formModel.major === '03') {
                                this.score_name = '摄影作品赏析'
                                this.score_name_1 = '摄影主题创作阐释'
                            } else if (this.formModel.major === '07' || this.formModel.major === '08') {
                                this.score_name = '面试单项分'
                                this.score_name_1 = '笔试单项分'
                            } else if (this.formModel.major === '02' || this.formModel.major === '09' || this.formModel.major === '04' || this.formModel.major === '06') {
                                this.show = false
                            } else {
                                this.score_name = '文艺常识'
                                this.score_name_1 = '故事编写'
                            }

                            // this.$KalixMessage.success(response.data.msg)
                        } else {
                            this.$KalixMessage.error(response.data.msg)
                        }
                    })
                }
                //  console.log(this.formModel.barCode)
            },
            cleanInfo() {
                this.formModel.examNumber = ''
                this.formModel.examName = ''
                this.formModel.identificationCard = ''
                this.formModel.major = ''
                this.formModel.province = ''
                this.formModel.university = ''
                this.formModel.address = ''
                this.formModel.phone = ''
            }
        }
    }
</script>

<style scoped lang="stylus">
    .el-form
        padding 30px 70px 30px 20px
</style>
